﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace API.Core.ActionResults
{
    public class CommonEdexResult : System.Web.Mvc.ActionResult
    {
        public bool Success { get; set; }
        public string Message { get; set; }

        public CommonEdexResult() {
            this.Success = true;
        }

        public CommonEdexResult(bool success, string message)
        {
            this.Success = success;
            this.Message = message;
        }
        
        public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
        {
            HttpContextBase httpContextBase = context.HttpContext;
            httpContextBase.Response.Buffer = true;
            httpContextBase.Response.Clear();

            httpContextBase.Response.ContentType = "application/json";

            var result = new API.Core.CommonSimpleResponse(this.Success, this.Message);
            httpContextBase.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.Indented));
        }
    }

    public class CommonEdexResult<T> : System.Web.Mvc.ActionResult
    {
        public T Data { get; set; }
        public CommonEdexResult() { }
        public CommonEdexResult(T data)
        {
            this.Data = data;
        }

        public override void ExecuteResult(System.Web.Mvc.ControllerContext context)
        {
            HttpContextBase httpContextBase = context.HttpContext;
            httpContextBase.Response.Buffer = true;
            httpContextBase.Response.Clear();

            httpContextBase.Response.ContentType = "application/json";

            var result = new API.Core.CommonSimpleDataResponse(this.Data);
            httpContextBase.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.Indented));
        }
    }
}